/**
  ******************************************************************************
  * File Name          : dclcdtsk.c
  * Description        : Code for freertos applications
  ******************************************************************************
  * @attention
  *
  ******************************************************************************
  */

/* Includes ------------------------------------------------------------------*/
#include "bsp.h"
#include "tskcfg.h"
#include "dclcd.h"

TaskHandle_t xDcLcd_Thd = NULL;
StaticTask_t xDcLcd_Tcb;
StackType_t  xDcLcd_Stk[DCLCD_STACK_SIZE];

static DcLcd_RecvStru dclcd_recv_buf_bck;
static DcLcd_SendStru dclcd_send_buf_bck;

void vDcLcd_Task(void * pvParameters)
{ 
  dclcd_uart_init();
  
  xGui_Thd = xTaskCreateStatic(vGui_Task, "gui", GUI_STACK_SIZE, (void *)1, \
                               GUI_TSK_PRIORITY, xGui_Stk, &xGui_Tcb);
  while(1)
  {
    if(xQueueReceive(dclcd_send_qhd, &dclcd_send_buf_bck, portMAX_DELAY) == pdTRUE)
    {
      if(dclcd_send_buf_bck.needreply != 0){
        xQueueReset(dclcd_recv_qhd);
      }
      
      dclcd_dma_send_buf(dclcd_send_buf_bck.buf, dclcd_send_buf_bck.cnt);  //dclcd_send_buf  dclcd_dma_send_buf

      if((dclcd_send_buf_bck.needreply != 0) || (dclcd_send_buf_bck.replycb != NULL))
      {
        if(xQueueReceive(dclcd_recv_qhd, &dclcd_recv_buf_bck, dclcd_send_buf_bck.reptimeout) == pdTRUE)
        {
          dclcd_send_buf_bck.replycb(dclcd_recv_buf_bck.buf, dclcd_recv_buf_bck.cnt);
        }
      }
    }
  }
}
